package edu.drexel.cs.eVoter.VoterClient;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;

public class VoteRequestPanel extends ClientAbstractPanel 
{
	private static final long serialVersionUID = 34745073027899104L;

	private JLabel            stateLabel = new JLabel("Select State:");
	private JComboBox<String> stateComboBox;
	private JLabel    		  voterLabel = new JLabel("Select Voter:");
	private JComboBox<String> voterComboBox;
	private JLabel            candidateLabel = new JLabel("Choose Candidate:");
	private JComboBox<String> candidateComboBox;
	private JButton   		  submitButton;
	
	private String[]          stateStrings = {"Alabama","Alaska","American Samoa","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","District of Columbia","Florida","Georgia","Guam","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Northern Marianas Islands ","Ohio","Oklahoma","Oregon","Pennsylvania","Puerto Rico","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia ","Virgin Islands ","Washington","West Virginia","Wisconsin","Wyoming "};;
	private String[]          candidateStrings = {"Mitt Romney", "Barack Obama", "Iron Man", "Hulk", "Jane Doe"};
	private String[]          voterStrings = { "Somebody 1", "Somebody 2", "Somebody 3", "Somebody 4", "Somebody 5" };
	
	public VoteRequestPanel(ServerInterface si) 
	{
		super(si);
		
		Box mainbox, b;
		
		mainbox = Box.createVerticalBox();
		
		b = Box.createHorizontalBox();
		b.add( stateLabel );
		stateComboBox = new JComboBox<String>( stateStrings );
		stateComboBox.addActionListener( new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e) 
			{
				processStateSelection( e );
			}
			
		});
		// set to disabled because it doesn't do anything
		stateComboBox.setEnabled(false);
		b.add( stateComboBox );
		
		mainbox.add( b );
		
		b = Box.createHorizontalBox();
		b.add( voterLabel );
		voterComboBox = new JComboBox<String>( voterStrings );
		voterComboBox.addActionListener( new ActionListener() 
		{	
			@Override
			public void actionPerformed(ActionEvent e) 
			{
				processVoterSelection( e );
			}
		});
		b.add( voterComboBox );
		
		mainbox.add( b );
		
		b = Box.createHorizontalBox();
		b.add( candidateLabel );
		candidateComboBox = new JComboBox<String>( candidateStrings );
		candidateComboBox.addActionListener( new ActionListener() 
		{	
			@Override
			public void actionPerformed(ActionEvent e) 
			{
				processCandidateSelection( e );
			}
		});
		b.add( candidateComboBox );
		
		mainbox.add( b );
		
		submitButton = new JButton( "Submit Vote" );
		submitButton.addActionListener( new ActionListener() 
		{	
			@Override
			public void actionPerformed(ActionEvent e) 
			{
				processSubmit( e );
			}
		});
		mainbox.add( submitButton );
		
		add( mainbox );
	}

	private void processStateSelection( ActionEvent event )
	{
		// can skip this for now 
	}
	
	private void processVoterSelection( ActionEvent event )
	{
		// can skip this for now 
	}
	
	private void processCandidateSelection( ActionEvent event )
	{
		// can skip this for now 
	}
	
	private void processSubmit( ActionEvent event )
	{
		String ID = voterComboBox.getSelectedItem().toString();
		String candidate = candidateComboBox.getSelectedItem().toString();
		String state = stateComboBox.getSelectedItem().toString();
		myServerInterface.vote( ID, candidate, state);
	}
	
	public void updateStates( List<String> states )
	{
		
	}
	
	public void updateVoters( List<String> voters )
	{
		
	}
	
	public void updateCandidates( List<String> candidates )
	{
		
	}

}
